package javabase.schoolwork.day6_07;

/**
 * @author fance
 * @date 2018/6/7 20:30
 */
class MyThreadInterrupt implements Runnable {
    @Override
    public void run() {
        System.out.println("1, in run method");

        try {
            Thread.sleep(10000);
            System.out.println("2, over sleep");
        } catch (InterruptedException e) {
            System.out.println("3 shut down");
            return;
        }

        System.out.println("4, normal out");
    }
}

class DaemonThread implements Runnable {
    @Override
    public void run() {
        while (true) {
            System.out.println(Thread.currentThread().getName() + " is running ..");

        }
    }
}
public class ThreadInterrupt {
    public static void main(String[] args) {
        /*MyThreadInterrupt threadInterrupt = new MyThreadInterrupt();

        Thread thread = new Thread(threadInterrupt,"son..");
        thread.start();

        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
*/
       // thread.interrupt();

        DaemonThread daemonThread = new DaemonThread();

        Thread thread = new Thread(daemonThread,"son..");
        thread.setDaemon(true);
        thread.start();
        try {
            Thread.sleep(10000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
